import requests
from lxml import etree
from requests.adapters import HTTPAdapter
s = requests.session()

# max_retries=3 重试3次
s.mount('http://',HTTPAdapter(max_retries=3))
s.mount('https://', HTTPAdapter(max_retries=3))

f=open("mgmrt.txt","a",encoding="utf-8")
url = "https://www.amazon.com/hz/leaderboard/hall-of-fame"
r = s.request("GET", url=url, timeout=15)
r.encoding = r.apparent_encoding
print(r.text)
html = etree.HTML(r.text)
result = html.xpath('//tr/td[2]/a[1]/@href')
print(len(result))
for line in result:
    f.write('https://www.amazon.com'+line+'\n')
    print('https://www.amazon.com'+line+'\n')
f.close()